<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.name"
            placeholder="菜品名称"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item>
                <el-select v-model="dataForm.sort" placeholder="请选择价格排序" clearable>
                    <el-option v-for="item in sort" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="getDataList()">{{
            $t("query")
          }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            v-if="$hasPermission('IsFoodSuggest:isfoodsuggest:save')"
            @click="addOrUpdateHandle()"
            >{{ $t("add") }}</el-button
          >
        </el-form-item>
        <!-- <el-form-item>
                <el-button type="primary" @click="exportHandle()">导出</el-button>
            </el-form-item> -->
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
        :height="he"
      >
        <el-table-column
          prop="name"
          label="菜品名称"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="coverImage"
          label="封面"
          header-align="center"
          min-width="120"
          align="center"
        >
          <template slot-scope="scope">
            <el-image
              :src="scope.row.coverImage"
              style="width: 100px; height: 100px"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('IsFoodSuggest:isfoodsuggest:update')"
              @click="addOrUpdateHandle(scope.row.id)"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('IsFoodSuggest:isfoodsuggest:delete')"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
    </div>
  </el-card>
</template>


<script>
var that;
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./good-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/sys/isfoodsuggest/page",
        getDataListIsPage: true,
        deleteURL: "/sys/isfoodsuggest",
        deleteIsBatch: true,
      },
      he: "auto",
      dataForm: {
        FOOD_ID:
          this.$store.state.user.superAdmin == 1
            ? ""
            : this.$store.state.user.MerchantId,
        name: "",
        order: "desc",
        orderField: "CREATE_DATE",
      },
    };
  },
  components: {
    AddOrUpdate,
  },
  created() {
    that = this;
  },
  watch:{
    dataList(newval, oldval) {
      if (newval != oldval) {
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 270px)";
        }, 500);
      }
    },
  },
  filters: {
    delScenicLabel(val) {
      let str = "";
      if (val && val.length != 0) {
        for (let i = 0; i < val.length; i++) {
          str += that.$getDictLabel("FishermanType", val[i]) + "，";
        }
        return str;
      }
    },
    imgfilter(val) {
      if (val) {
        return val.split(",")[0];
      }
    },
  },
  methods: {},
};
</script>
